<template>
  <div class="app-container">
    <template>
      <div class="right-detail">
        <div class="cbox">
          <el-form
            class="form"
            :model="queryParam"
            ref="queryParam"
            :rules="rules"
            label-width="9rem"
            size="mini"
          >
            <el-row :gutter="12" class="row">
              <el-col :span="6">
                <el-form-item size="mini" label="标的编号：" prop="bidCode" label-width="85px">
                  <el-input clearable v-model="queryParam.bidCode" size="mini" style="width:180px"></el-input>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="5">
                <el-form-item size="mini" label="报名状态：" prop="enrollStatus" label-width="100px">
                <el-select clearable v-model="queryParam.enrollStatus" style="width: 100%" placeholder="请选择">
                  <el-option v-for="(item, index) in statusList" :key="index" :value="item.code" :label="item.name">
                  </el-option>
                </el-select>
              </el-form-item>
              </el-col>-->
              <el-col :span="2">
                <el-form-item label-width="10px">
                  <el-button @click="searchType" type="primary">查询</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <split-pane split="horizontal" v-on:resize="resize" :default-percent="55" :max-percent="80">
          <!-- 上半部分 -->
          <template slot="paneL">
            <div class="top-type" ref="topType">
              <!-- <div class="btn-area" ref="btnArea">
                <el-button plain size="mini" type="primary" v-if="isAuth('auditButton')" @click="auditButton">报名</el-button>
                <el-button plain size="mini" type="primary" v-if="isAuth('delAuditButton')" @click="delAuditButton">取消报名</el-button>
              </div>-->

              <!-- 状态（E-启用 N-未启用 D-停用） -->
              <el-table
                :data="TypeList"
                :height="typeHeight"
                highlight-current-row
                class="demand"
                @row-click="getCurrentTypeRow"
                border
                :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{}"
              >
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  type="index"
                  label="序号"
                  align="center"
                  width="60"
                >
                  <template slot-scope="scope">
                    <span>{{(Pagination.currentPage - 1) * Pagination.pageSize + scope.$index + 1}}</span>
                  </template>
                </el-table-column>
                <!-- <el-table-column align="center" label="报名状态" prop="enrollStatus" width="80" show-overflow-tooltip>
                <template slot-scope="scope">
                    <span v-if="scope.row.enrollStatus =='N'">未报名</span>
                    <span v-if="scope.row.enrollStatus =='Y'">已报名</span>
                  </template>
                </el-table-column>-->
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidCode"
                  width="120"
                  align="center"
                  label="标的编号"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidType"
                  width="80"
                  align="center"
                  label="标的类型"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidName"
                  align="center"
                  width="220"
                  label="标的名称"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidAmount"
                  width="120"
                  align="center"
                  label="运输总量（吨）"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidSignupStart"
                  width="160"
                  align="center"
                  label="竞价报名开始时间"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidSignupEnd"
                  width="160"
                  align="center"
                  label="竞价报名结束时间"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidBiddingStart"
                  width="160"
                  align="center"
                  label="竞价开始时间"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidBiddingEnd"
                  width="160"
                  align="center"
                  label="竞价结束时间"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidOffer"
                  width="150"
                  align="center"
                  label="单价竞价范围（元/吨）"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="bidQuotations"
                  align="left"
                  label="竞价方式"
                ></el-table-column>
                <!-- <el-table-column size="mini" show-overflow-tooltip prop="bidAppointMan" align="left" label="供应商指定人"></el-table-column> -->
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  width="120"
                  prop="dptName"
                  label="标的来源"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  header-align="left"
                  align="left"
                  prop="bidRemark"
                  label="备注"
                ></el-table-column>
              </el-table>
              <div>
                <el-pagination
                  class="pagination"
                  small
                  background
                  ref="pagination"
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="Pagination.currentPage"
                  :page-sizes="Pagination.pageSizeList"
                  :page-size="Pagination.pageSize"
                  :layout="Pagination.layout"
                  :total="Pagination.total"
                ></el-pagination>
              </div>
            </div>
          </template>

          <!-- 下半部分 -->
          <template slot="paneR">
            <div class="codeNumberCode" style="background-color: #fff;">需求信息</div>
            <div class="bottom-code" ref="bottomCode" style="background-color: #fff;">
              <div class="btn-area" ref="detlArea">
                <buttonName @clickEvent="clickEventDom"></buttonName>
                <!-- <el-button plain size="mini" type="primary" v-if="isAuth('auditButton')" @click="auditButton">报名</el-button>
                <el-button plain size="mini" type="primary" v-if="isAuth('delAuditButton')" @click="delAuditButton">取消报名</el-button>-->
              </div>
              <el-table
                :height="detlHeight"
                :data="currentCodeList"
                highlight-current-row
                @row-click="getCurrentCodeRow"
                border
                @selection-change="rowSelectionChange"
                :header-cell-style="{
                    textAlign: 'center'
                  }"
                :cell-style="{}"
              >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column
                  type="index"
                  show-overflow-tooltip
                  align="center"
                  width="60%"
                  label="序号"
                ></el-table-column>
                <el-table-column
                  align="center"
                  label="报名状态"
                  prop="signupStatus"
                  width="100"
                  show-overflow-tooltip
                >
                  <template slot-scope="scope">
                    <span v-if="scope.row.signupStatus =='N'">未报名</span>
                    <span v-if="scope.row.signupStatus =='Y'">已报名</span>
                  </template>
                </el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  width="120"
                  align="left"
                  prop="demandCode"
                  label="需求编号"
                ></el-table-column>
                <el-table-column show-overflow-tooltip align="center" prop="brand" label="货物品牌"></el-table-column>
                <el-table-column show-overflow-tooltip align="center" prop="dailyOutput" label="规格"></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="product"
                  align="center"
                  label="产品大类"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="kind"
                  align="center"
                  label="品种"
                ></el-table-column>
                <!-- <el-table-column show-overflow-tooltip align="center" prop="goodsCode" label="货物编码"></el-table-column> -->
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  prop="transportType"
                  label="运输类型"
                ></el-table-column>
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="transportMode"
                  align="center"
                  label="运输方式"
                ></el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  align="center"
                  prop="transportQuantity"
                  width="120"
                  label="运输数量(吨)"
                ></el-table-column>
                <!-- <el-table-column show-overflow-tooltip align="center" prop="specialRequire" label="特殊要求"></el-table-column> -->
                <!-- <el-table-column show-overflow-tooltip align="center" width="120" prop="dptName" label="需求来源"></el-table-column> -->
                <el-table-column
                  size="mini"
                  show-overflow-tooltip
                  prop="remark"
                  align="center"
                  label="备注"
                ></el-table-column>
                <el-table-column show-overflow-tooltip align="center" width="150" label="操作">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="primary"
                      plain
                      @click="showTransportMethod(scope.row)"
                    >线路详情</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!-- <div>
                <el-pagination class="pagination" small background
                  @size-change="handleSizeChangeA"
                  @current-change="handleCurrentChangeA"
                  :current-page="currentPage"
                  :page-sizes="[30, 60, 90, 120]"
                  :page-size="30"
                  layout="sizes, prev, pager, next, jumper, total"
                  :total="pageTotal">
                </el-pagination>
              </div>-->
            </div>
          </template>
        </split-pane>
      </div>
    </template>

    <!-- 报名弹框 -->
    <el-dialog
      width="70%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-el-drag-dialog
      title="报名信息"
      :visible.sync="RefTypeDialogVisible"
      v-if="RefTypeDialogVisible"
      :before-close="handleTypeDialogClose"
    >
      <el-form
        label-position="right"
        :model="RefTypeData"
        ref="RefTypeData"
        :rules="RefTypeDataRules"
        label-width="10rem"
        size="mini"
      >
        <!-- <el-form :model="dialogForm" size="mini" ref="dialogForm" label-width="10rem"> -->
        <el-row class="dialog-row">
          <el-col :span="8">
            <el-form-item label="标的编号:" prop="bidCode">
              <el-input v-model="RefTypeData.bidCode" readonly="ture"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标的类型:" prop="bidType">
              <el-select
                v-model="RefTypeData.bidType"
                style="width: 100%"
                placeholder="请选择类型"
                disabled="ture"
                filterable
                clearable
              ></el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="标的名称:" prop="bidName">
              <el-input
                v-model="RefTypeData.bidName"
                readonly="ture"
                placeholder="请输入标的名称"
                clearable
                filterable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="dialog-row">
          <el-col :span="8">
            <el-form-item label="运输总量:" prop="bidAmount">
              <el-input
                v-model="RefTypeData.bidAmount"
                readonly="ture"
                placeholder="请输入数量"
                filterable
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="竞价方式:" prop="bidQuotations">
              <el-input v-model="RefTypeData.bidQuotations" readonly="ture" clearable filterable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单价竞价范围:" prop="bidOffer">
              <el-input v-model="RefTypeData.bidOffer" readonly="ture" maxlength="8" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注:" prop="bidRemark">
              <el-input type="textarea" readonly="ture" v-model="RefTypeData.bidRemark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- </el-form> -->

      <div class="tableTitle">需求信息</div>
      <div>
        <el-table
          :data="currentCodeList"
          :height="detlHeight"
          highlight-current-row
          border
          @selection-change="rowSelectionChange"
          :header-cell-style="{
              textAlign: 'center'
            }"
          :cell-style="{}"
        >
          <!-- <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column  align="center" prop="zjcz" label="押金操作" show-overflow-tooltip width="250" sortable>
              <template slot-scope="scope">
                <el-link type="primary" @click="upload" :underline="false">押金图片上传</el-link>&nbsp;&nbsp;
                <el-link type="primary" @click="viewPic(scope.row)" :underline="false">押金图片查看</el-link>
              </template>
          </el-table-column>-->
          <el-table-column type="index" show-overflow-tooltip align="center" width="60%" label="序号"></el-table-column>
          <el-table-column
            size="mini"
            show-overflow-tooltip
            width="120"
            align="left"
            prop="demandCode"
            label="需求编号"
          ></el-table-column>
          <el-table-column show-overflow-tooltip align="center" prop="brand" label="货物品牌"></el-table-column>
          <el-table-column show-overflow-tooltip align="center" prop="dailyOutput" label="规格"></el-table-column>
          <el-table-column
            size="mini"
            show-overflow-tooltip
            prop="product"
            align="center"
            label="产品大类"
          ></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip prop="kind" align="center" label="品种"></el-table-column>
          <!-- <el-table-column show-overflow-tooltip align="center" prop="goodsCode" label="货物编码"></el-table-column> -->
          <el-table-column show-overflow-tooltip align="center" prop="transportType" label="运输类型"></el-table-column>
          <el-table-column
            size="mini"
            show-overflow-tooltip
            prop="transportMode"
            align="center"
            label="运输方式"
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            align="center"
            width="120"
            prop="transportQuantity"
            label="运输数量(吨)"
          ></el-table-column>
          <!-- <el-table-column show-overflow-tooltip align="center" prop="specialRequire" label="特殊要求"></el-table-column> -->
          <el-table-column
            size="mini"
            show-overflow-tooltip
            prop="remark"
            align="center"
            label="备注"
          ></el-table-column>
          <el-table-column show-overflow-tooltip align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                plain
                @click="showTransportMethod(scope.row)"
              >线路详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="RefTypeDialogVisible = false">关闭</el-button>
        <el-button size="mini" type="primary" @click="signupTrue">确认报名</el-button>
      </div>
    </el-dialog>

    <el-dialog
      width="40%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-el-drag-dialog
      title="线路详情"
      :visible.sync="tranDialogInfoDialogVisible"
      v-if="tranDialogInfoDialogVisible"
      :before-close="handleTypeDialogClose"
    >
      <el-table
        :data="tranDialogInfoList"
        :height="detlHeight"
        highlight-current-row
        border
        :header-cell-style="{
              textAlign: 'center'
            }"
        :cell-style="{}"
      >
        <el-table-column type="index" width="60" align="center" label="序号"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="起始地" prop="site"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="目的地" prop="destination"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button
          size="mini"
          type="primary"
          @click="tranDialogInfoDialogVisible = false;tranDialogInfoList = []"
        >关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryBiddingList,
  queryBiddingStatusList,
  auditBiddingMethod,
  bidListDetail,
  signupBiddingMethod,
  delSignupMethod,
  queryDemandLine,
  queryBondList,
  querytSignUpSugar,
  codeTableListb,
  addCodeTable,
  editCodeTable,
  delCodeTable,
  codeTableListA,
  addCodeTableA,
  addCodeTableXL,
  editCodeTableA,
  delCodeTableA
} from '@/request/api'
import resizeMixin from '@/mixins/resize'
import isAuth from '@/mixins/buttonAuth'
import paginationMixin from '@/mixins/pagination'
import store from '@/store'
import scrollChange from '@/utils/onscroll.js'
import buttonName from '@/components/buttonName/button-name.vue'
export default {
  mixins: [resizeMixin, paginationMixin, isAuth],
  data() {
    var RVNAME = (rule, value, callback) => {
      // 获得字符串实际长度，中文2，英文1
      var realLength = 0,
        len = value.length,
        charCode = -1
      for (var i = 0; i < len; i++) {
        charCode = value.charCodeAt(i)
        if (charCode >= 0 && charCode <= 128) realLength += 1
        else realLength += 2
      }
      if (realLength > 32) {
        return callback(new Error('最多为32位'))
        // this.companyName = cutstr(this.companyName, 60);
      } else {
        return callback()
      }
    }
    var RVREMARK = (rule, value, callback) => {
      // 获得字符串实际长度，中文2，英文1
      var realLength = 0,
        len = value.length,
        charCode = -1
      for (var i = 0; i < len; i++) {
        charCode = value.charCodeAt(i)
        if (charCode >= 0 && charCode <= 128) realLength += 1
        else realLength += 2
      }
      if (realLength > 128) {
        return callback(new Error('最多为128位'))
        // this.companyName = cutstr(this.companyName, 60);
      } else {
        return callback()
      }
    }
    return {
      queryParam: {
        bidCode: '', // 标的编号
        enrollStatus: '' // 标的报名状态
      },
      diaTableData: [], // 弹出框需求信息信息
      statusList: [
        { code: 'N', name: '未报名' },
        { code: 'Y', name: '已报名' }
      ],
      kinds: {
        BROW: '赤砂糖',
        TWOW: '二级白砂糖',
        ONEW: '一级白砂糖'
      },
      selNoApproveArray: [], //未报名的信息
      selApproveArray: [], //已报名的信息

      sugarIds: [], //需求id数组
      currentPage: 1,
      pageSize: 30,
      pageTotal: 0,

      currentRow: '',
      codeentRow: '',
      typeHeight: -1,
      detlHeight: -1,
      CodeRCTUUID: false,
      CodeRVDOMAIN: false,
      checkedY: true,
      checkedN: false,
      flt: {
        rvDomain: '',
        rvName: ''
      },
      copyDomain: '',
      copyName: '',
      rleTypes: [],
      TypeMap: {
        updateType: 'baseCode.editClassify',
        createType: 'baseCode.addClassify'
      },
      CodeMap: {
        updateCode: 'baseCode.editCode',
        createCode: 'baseCode.addCode'
      },
      TypeDialogStatus: '',
      CodeDialogStatus: '',
      currentNode: {},
      currentType: {},
      TypeList: [],
      currentCodeList: [],
      currentCode: {},
      tranDialogInfoList: [],
      tranDialogInfoDialogVisible: false, //线路详情Dialog
      RefTypeDialogVisible: false, // 报名 Dialog
      RefCodeDialogVisible: false, // 基础代码 Dialog
      dialogForm: {},
      dialogText: {
        title: '',
        show: false,
        button: {
          t: '',
          f: ''
        },
        qeuryButtonShow: false,
        paginationShow: false
      },
      // 代码分类
      RefTypeData: {}, // 代码分类 dialog内的form([A-Z]|\d)[0-9a-zA-Z]
      rules: {
        RV_DOMAIN: [
          { min: 1, max: 4, message: '至多输入4 个字符', trigger: 'change' },
          {
            pattern: /^([^\u4e00-\u9fa5])+$/,
            message: '禁止输入中文',
            trigger: 'change'
          }
        ],
        RV_NAME: [
          { validator: RVNAME, trigger: 'change' },
          {
            pattern: /^([0-9a-zA-Z\u4e00-\u9fa5])+$/,
            message: '只能输入中文字母数字',
            trigger: 'change'
          }
        ]
      },
      RefTypeDataRules: {
        rvDomain: [
          // { validator: RVDOMAIN, trigger: 'change' },
          { min: 1, max: 4, message: '至多输入4个字符', trigger: 'change' },
          { required: true, message: '请填写类型编号', trigger: 'blur' }
          // {
          //   pattern: /^([^\u4e00-\u9fa5])+$/,
          //   message: '禁止输入中文',
          //   trigger: 'change'
          // }
        ],
        rvName: [
          { required: true, message: '请填写类型名称', trigger: 'blur' },
          { validator: RVNAME, trigger: 'change' },
          {
            pattern: /^([0-9a-zA-Z\u4e00-\u9fa5])+$/,
            message: '只能输入中文字母数字',
            trigger: 'change'
          }
        ],
        rvIsvalid: [{ required: true, message: '请选择有效标志', trigger: 'blur' }],
        rvRemark: [{ validator: RVREMARK, trigger: 'change' }]
      },
      // 基础代码
      RefCodeData: {}, // 代码分类 dialog内的form
      RefCodeDataRules: {
        rvDomain: [{ required: true, message: '请选择代码类型', trigger: 'change' }],
        rvLowValue: [
          { min: 1, max: 4, message: '至多输入4个字符', trigger: 'change' },
          {
            pattern: /^([^\u4e00-\u9fa5])+$/,
            message: '禁止输入中文',
            trigger: 'change'
          },
          { required: true, message: '请填写代码编号', trigger: 'blur' }
        ],
        rvCmeaning: [
          { required: true, message: '请填写代码名称', trigger: 'blur' },
          { validator: RVNAME, trigger: 'change' }
          // {
          //   pattern: /^([0-9a-zA-Z\u4e00-\u9fa5])+$/,
          //   message: '只能输入中文字母数字',
          //   trigger: 'change'
          // }
        ],
        rvIsvalid: [{ required: true, message: '请选择有效标志', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.resize = () => {
      this.typeHeight = this.$refs.topType.offsetHeight - 40
      // 70
      this.detlHeight = this.$refs.bottomCode.offsetHeight - 100
      // 130
    }
  },
  mounted() {
    let demandWrapper = document.querySelector('.demand .el-table__body-wrapper') // 新增滚动条监听事件
    scrollChange(demandWrapper)
  },
  beforeMount() {
    this.refreshList()
  },
  computed: {
    grandson() {
      var dataList = []
      var number
      var arr = this.$route.path.split('/')
      number = arr.length - 1
      dataList = this.$store.state.user.permList
      for (var i = 0; i < dataList.length; i++) {
        for (var f = 0; f < dataList[i].Children.length; f++) {
          if (dataList[i].Children[f].MDL_CODE == arr[number]) {
            return dataList[i].Children[f].Grandson
          }
        }
      }
      return []
    },
    disableType() {
      return this.TypeDialogStatus === 'updateType'
    }
  },
  methods: {
    //导出
    outExcel() {
      if (this.currentCodeList.length == 0) {
        this.$alert('请选择需要导出的信息！', '提示', {
          confirmButtonText: '确定'
        })
        return
      }
      var filename = this.RefTypeData.bidCode + '-' + this.RefTypeData.bidName
      import('@/vendor/Export2Excel').then(excel => {
        const tHeader = ['序号', '需求编号', '吨数', '品种', '规格', '来源', '品牌', '竞价状态', '当前出价', '当前名次', '起始地', '目的地']
        const filterVal = [
          'index',
          'demandCode',
          'transportQuantity',
          'kind',
          'dailyOutput',
          'dptName',
          'brand',
          'biddingStatus',
          'biddingPrice',
          'rank',
          'site',
          'destination'
        ]
        const list = this.currentCodeList
        const data = this.formatJson(filterVal, list)
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: filename,
          autoWidth: true
        })
        this.downloadLoading = false
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v, index) =>
        filterVal.map(j => {
          if (j === 'biddingStatus') {
            if (v[j] === 'Y') {
              return '已竞价'
            } else {
              return '未竞价'
            }
          }
          if (j === 'index') {
            return index + 1
          }
          return v[j]
        })
      )
    },
    dialogBeforeClose(done) {
      this.$confirm('确认关闭?')
        .then(() => {
          done()
        })
        .catch(() => {})
    },

    checkCode() {
      this.flt.RV_DOMAIN = this.flt.RV_DOMAIN.replace(/[^a-zA-Z]/g, '')
    },
    typecheck() {
      this.RefTypeData.RV_DOMAIN = this.RefTypeData.RV_DOMAIN.replace(/[^a-zA-Z]/g, '')
    },
    codecheck() {
      this.RefCodeData.RV_DOMAIN = this.RefCodeData.RV_DOMAIN.replace(/[^a-zA-Z]/g, '')
    },
    uppercase(key) {
      this.$refs.typePagination.lastEmittedPage = 1
      this.$refs.codePagination.lastEmittedPage = 1
      this.flt[key] = this.flt[key].toUpperCase()
    },
    // typeuppercase(key) {
    //   this.RefTypeData[key] = this.RefTypeData[key].toUpperCase()
    // },
    codeuppercase(key) {
      this.RefCodeData[key] = this.RefCodeData[key].toUpperCase()
    },
    getFltType() {
      addCodeTableXL({}).then(res => {
        if (res.success === '1') {
          this.rleTypes = res.data
        }
      })
    },
    searchType() {
      this.$refs.queryParam.validate(valid => {
        if (valid) {
          this.Pagination.currentPage = 1
          this.getList(this.Pagination.currentPage, this.Pagination.pageSize, this.updatePaginationTotal)
        }
      })
    },
    //获取列表
    getList(currentPage, pageSize, updateTotal) {
      this.currentCodeList = []
      this.currentType = {}
      this.currentCode = []
      this.RefTypeData = {}
      queryBiddingStatusList({
        bidCode: this.queryParam.bidCode,
        enrollStatus: this.queryParam.enrollStatus,
        bidAuditstatus: 'Y',
        bidBiddingstatus: 'Y',
        PageIndexs: this.Pagination.currentPage.toString(),
        PageSizes: this.Pagination.pageSize.toString()
      }).then(response => {
        this.TypeList = response.data
        updateTotal(Number(response.total))
      })
    },

    // 报名
    auditButton() {
      if (Object.keys(this.currentType).length == 0) {
        this.$alert('请选择需要报名的信息！', '提示', {
          confirmButtonText: '确定'
        })
        return
      }
      let allcount = 0
      for (let index = 0; index < this.currentCodeList.length; index++) {
        if (this.currentCodeList[index].signupStatus === 'Y') {
          allcount++
        }
      }
      if (allcount != 0) {
        this.$alert('选中信息存在已报名信息，请只选择未报名的信息', '提示', {
          confirmButtonText: '确定'
        })
        return
      }

      // if (this.selNoApproveArray.length < 1) {
      //   if (Object.keys(this.currentCode).length == 0) {
      //     this.$alert('请选择未报名的信息！', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     this.sugarIds = []
      //     return
      //   }

      //   if (this.currentCode.signupStatus === 'Y') {
      //     this.$alert('请选择未报名的信息！', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     this.sugarIds = []
      //     return
      //   }
      //   this.sugarIds.push(this.currentCode.sugarId)
      // } else {
      //   if (this.selNoApproveArray.length == 0) {
      //     this.$alert('请选择未报名的信息！', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     this.sugarIds = []
      //     return
      //   }
      //   if (this.selApproveArray.length != 0) {
      //     this.$alert('选中信息存在已报名信息，请只选择未报名的信息', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     this.sugarIds = []
      //     return
      //   }
      // }

      let date = new Date()
      let startime = new Date(Date.parse(this.RefTypeData.bidSignupStart))
      let endtime = new Date(Date.parse(this.RefTypeData.bidSignupEnd))
      if (startime > date) {
        this.$alert('该报名还未开始，敬请期待！', '提示', {
          confirmButtonText: '确定'
        })
        this.sugarIds = []
        return
      }
      if (date > endtime) {
        this.$alert('十分抱歉，该报名已经结束', '提示', {
          confirmButtonText: '确定'
        })
        this.sugarIds = []
        return
      }
      queryBondList({
        fltId: store.state.user.FLT_UUID_DX_H,
        bidId: this.RefTypeData.bidId,
        bondStatus: 'Y'
      }).then(response => {
        if (response.data.length > 0) {
          // this.RefTypeDialogVisible = true
          this.$confirm('您确定要报名该信息吗？', '提示', {
            confirmButtonText: '确定'
          }).then(() => {
            signupBiddingMethod({
              sugarIds: this.sugarIds,
              isdel: '0',
              bidId: this.RefTypeData.bidId
            }).then(res => {
              if (res.success === '1') {
                this.$message({
                  type: 'success',
                  message: '报名成功'
                })
                this.getCurrentTypeRow(this.RefTypeData)
                this.sugarIds = []
              }
            })
          })
        } else {
          this.$alert('还未缴纳保证金，请缴纳后再报名！', '提示', {
            confirmButtonText: '确定'
          })
          this.sugarIds = []
        }
      })
    },
    // 取消报名
    delAuditButton() {
      if (Object.keys(this.currentType).length == 0) {
        this.$alert('请选择需要取消报名的信息！', '提示', {
          confirmButtonText: '确定'
        })
        return
      }
      // if (this.selApproveArray.length < 1) {
      //   if (Object.keys(this.currentCode).length == 0) {
      //     this.$alert('请选择已报名的信息！', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     return
      //   }

      //   if (this.currentCode.signupStatus === 'N') {
      //     this.$alert('请选择已报名的信息！', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     return
      //   }
      //   this.sugarIds.push(this.currentCode.sugarId)
      // } else {
      //   if (this.selApproveArray.length == 0) {
      //     this.$alert('请选择已报名的信息！', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     return
      //   }
      //   if (this.selNoApproveArray.length != 0) {
      //     this.$alert('选中信息存在未报名信息，请只选择已报名的信息', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     return
      //   }
      // }

      let date = new Date()
      let startime = new Date(Date.parse(this.RefTypeData.bidSignupStart))
      let endtime = new Date(Date.parse(this.RefTypeData.bidSignupEnd))
      if (startime > date) {
        this.$alert('该报名还未开始，敬请期待！', '提示', {
          confirmButtonText: '确定'
        })
        return
      }
      if (date > endtime) {
        this.$alert('十分抱歉，该报名已经结束', '提示', {
          confirmButtonText: '确定'
        })
        return
      }

      this.$confirm('您确定要取消该报名吗？', '提示', {
        confirmButtonText: '确定'
      }).then(() => {
        let date = new Date()
        let startime = new Date(Date.parse(this.RefTypeData.bidSignupStart))
        let endtime = new Date(Date.parse(this.RefTypeData.bidSignupEnd))
        if (startime > date) {
          this.$alert('该报名还未开始，敬请期待！', '提示', {
            confirmButtonText: '确定'
          })
          return
        }
        if (date > endtime) {
          this.$alert('十分抱歉，该报名已经结束', '提示', {
            confirmButtonText: '确定'
          })
          return
        }
        delSignupMethod({ sugarIds: this.sugarIds, isdel: '1' }).then(res => {
          if (res.success === '1') {
            this.$message({
              type: 'success',
              message: '取消报名成功'
            })
            this.getCurrentTypeRow(this.RefTypeData)
            this.sugarIds = []
          }
        })
      })
    },

    // 确认报名
    signupTrue() {
      let date = new Date()
      let startime = new Date(Date.parse(this.RefTypeData.bidSignupStart))
      let endtime = new Date(Date.parse(this.RefTypeData.bidSignupEnd))
      if (startime > date) {
        this.$alert('该报名还未开始，敬请期待！', '提示', {
          confirmButtonText: '确定'
        })
        return
      }
      if (date > endtime) {
        this.$alert('十分抱歉，该报名已经结束', '提示', {
          confirmButtonText: '确定'
        })
        return
      }
      signupBiddingMethod({
        // sugarIds:this.sugarIds,
        isdel: '0',
        bidId: this.RefTypeData.bidId
      }).then(res => {
        if (res.success === '1') {
          this.$message({
            type: 'success',
            message: '报名成功'
          })
          this.RefTypeDialogVisible = false
          this.RefTypeData = {}
          this.refreshList()
        }
      })
    },

    getCurrentTypeRow(row) {
      this.sugarIds = []
      this.currentCode = []
      this.currentPage = 1
      this.pageSize = 30
      this.pageTotal = 0
      this.currentType = row
      this.RefTypeData = Object.assign({}, row)
      querytSignUpSugar({
        bidId: row.bidId
      }).then(res => {
        if (res.success == 1) {
          this.currentCodeList = res.data
          this.sugarIds = this.currentCodeList.map(x => {
            return x.sugarId
          })

          // this.currentCodeList.forEach(element => {
          //     if(this.RefTypeData.sugarIds.includes(element.sugarId)){
          //        element.signupStatus = 'Y'
          //     }else{
          //        element.signupStatus = 'N'
          //     }
          // });
        }
      })
    },

    //调取父组件方法
    clickEventDom(item) {
      if (item.mdlCode === 'auditButton') {
        this.auditButton()
      } else if (item.mdlCode === 'delAuditButton') {
        this.delAuditButton()
      } else if (item.mdlCode === 'biddingButtonB') {
        this.outExcel()
      }
    },

    // dialog 查看线路详细信息
    showTransportMethod(val) {
      this.tranDialogInfoList[0] = val
      // queryDemandLine({
      //   sugarId: val.sugarId
      // }).then(res => {
      //   if (res.success == 1) {
      //     this.tranDialogInfoList = res.data
      //   }
      // })
      this.tranDialogInfoDialogVisible = true
    },

    // 获取当前选中行(多行)
    rowSelectionChange(val) {
      this.selNoApproveArray = []
      this.selApproveArray = []
      if (val.length > 0) {
        for (var i = 0; i < val.length; i++) {
          if (val[i].signupStatus == 'Y') {
            this.selApproveArray.push(val[i])
          }
          if (val[i].signupStatus == 'N') {
            this.selNoApproveArray.push(val[i])
          }
        }
      }

      this.sugarIds = []
      val.forEach(element => {
        this.sugarIds.push(element.sugarId)
      })
    },

    // 点击基础代码表格的一行，获取到当前行的信息
    getCurrentCodeRow(row) {
      this.codeentRow = '1'
      this.currentCode = row
    },

    handleSizeChangeA(val) {
      this.pageSize = val
      this.getRefCode()
    },
    handleCurrentChangeA(val) {
      this.currentPage = val
      this.getRefCode()
    },

    handleTypeDialogClose() {
      this.RefTypeDialogVisible = false
      this.tranDialogInfoDialogVisible = false
    },
    handleCodeDialogClose() {
      this.RefCodeDialogVisible = false
    },
    // restet 基础代码
    resetRefCode() {
      return (this.RefCodeData = {
        // RCT_UUID: '',
        // RV_DOMAIN: '',
        // RV_CMEANING: '',
        // RV_NAME: '',
        // RV_ISVALID: 'Y',
        rvDomain: '',
        rvTerId: '-1',
        rvLowValue: '',
        rvCmeaning: '',
        rvIsvalid: 'Y'
        // rvInsertuser:'',
        // rvLstupduser:'',
      })
    }
  },
  components: {
    buttonName
  }
}
</script>

<style lang="scss" scoped>
::v-deep .splitter-pane-resizer.horizontal {
  margin-top: -15px;
}
.app-container {
  overflow: hidden;
  background-color: #fff;
  position: relative;
  height: 100%;
}
.tree {
  padding-right: 20px;
  font-size: 1.4rem;
}
.right-detail {
  height: 100%;
  .top-type {
    width: 100%;
    height: 100%;
    table {
      max-width: 100%;
      font-size: 1.4rem;
    }
  }
  .bottom-code {
    width: 100%;
    height: 100%;
  }
}
.codeNumberCode {
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 20px;
}
.basicInfoBox {
  border: 1px solid #cccccc;
  border-radius: 5px;
  padding-top: 25px;
  padding-bottom: 10px;
}
</style>
